﻿/**** ApplicationLogging Database *****/
USE [master]
GO

/****** Object:  Database [ApplicationLogging] ******/
CREATE DATABASE [ApplicationLogging]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'ApplicationLogging_Data', FILENAME = N'G:\SQLData\ApplicationLogging.MDF' , SIZE = 32768000KB , MAXSIZE = UNLIMITED, FILEGROWTH = 102400KB )
 LOG ON 
( NAME = N'ApplicationLogging_Log', FILENAME = N'H:\SQLLog\ApplicationLogging_1.ldf' , SIZE = 10242048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 102400KB )
GO

ALTER DATABASE [ApplicationLogging] SET COMPATIBILITY_LEVEL = 120
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [ApplicationLogging].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO

ALTER DATABASE [ApplicationLogging] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [ApplicationLogging] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [ApplicationLogging] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [ApplicationLogging] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [ApplicationLogging] SET ARITHABORT OFF 
GO

ALTER DATABASE [ApplicationLogging] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [ApplicationLogging] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [ApplicationLogging] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [ApplicationLogging] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [ApplicationLogging] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [ApplicationLogging] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [ApplicationLogging] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [ApplicationLogging] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [ApplicationLogging] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [ApplicationLogging] SET  DISABLE_BROKER 
GO

ALTER DATABASE [ApplicationLogging] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [ApplicationLogging] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [ApplicationLogging] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [ApplicationLogging] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [ApplicationLogging] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [ApplicationLogging] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [ApplicationLogging] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [ApplicationLogging] SET RECOVERY SIMPLE 
GO

ALTER DATABASE [ApplicationLogging] SET  MULTI_USER 
GO

ALTER DATABASE [ApplicationLogging] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [ApplicationLogging] SET DB_CHAINING OFF 
GO

ALTER DATABASE [ApplicationLogging] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO

ALTER DATABASE [ApplicationLogging] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO

ALTER DATABASE [ApplicationLogging] SET DELAYED_DURABILITY = DISABLED 
GO

ALTER DATABASE [ApplicationLogging] SET  READ_WRITE 
GO
USE [ApplicationLogging]
GO

/****** Object:  Table [dbo].[Applications]    Script Date: 3/8/2016 8:45:40 AM ******/
DROP TABLE [dbo].[Applications]
GO

/****** Object:  Table [dbo].[Applications]    Script Date: 3/8/2016 8:45:40 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Applications](
	[ApplicationID] [int] NOT NULL,
	[ApplicationName] [varchar](50) NOT NULL,
	[RetentionPeriodDays] [int] NOT NULL CONSTRAINT [DF_Applications_RetentionPeriodDays]  DEFAULT (90),
	[ADGroup] [varchar](100) NULL,
 CONSTRAINT [PK_Applications] PRIMARY KEY CLUSTERED 
(
	[ApplicationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
USE [ApplicationLogging]
GO

/****** Object:  Table [dbo].[EventTypes]    Script Date: 3/8/2016 8:46:33 AM ******/
DROP TABLE [dbo].[EventTypes]
GO

/****** Object:  Table [dbo].[EventTypes]    Script Date: 3/8/2016 8:46:33 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[EventTypes](
	[EventTypePK] [int] NOT NULL,
	[EventTypeDescription] [varchar](50) NOT NULL,
 CONSTRAINT [PK_EventTypes] PRIMARY KEY CLUSTERED 
(
	[EventTypePK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO 
USE [ApplicationLogging]
GO

ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_Events_Applications]
GO

/****** Object:  Table [dbo].[Events]    Script Date: 3/8/2016 8:47:17 AM ******/
DROP TABLE [dbo].[Events]
GO

/****** Object:  Table [dbo].[Events]    Script Date: 3/8/2016 8:47:17 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Events](
	[EventID] [int] IDENTITY(1,1) NOT NULL,
	[TimeStamp] [datetime] NOT NULL CONSTRAINT [DF_Events_TimeStamp]  DEFAULT (getdate()),
	[ApplicationIDFK] [int] NOT NULL,
	[EventType] [int] NOT NULL,
	[EventDescription] [varchar](255) NULL,
	[UserID] [varchar](30) NULL,
	[URL] [varchar](255) NULL,
	[IPAddress] [varchar](50) NULL,
 CONSTRAINT [PK_Events] PRIMARY KEY CLUSTERED 
(
	[EventID] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Events]  WITH NOCHECK ADD  CONSTRAINT [FK_Events_Applications] FOREIGN KEY([ApplicationIDFK])
REFERENCES [dbo].[Applications] ([ApplicationID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Events] CHECK CONSTRAINT [FK_Events_Applications]
GO
USE [ApplicationLogging]
GO

ALTER TABLE [dbo].[EventDetails] DROP CONSTRAINT [FK_EventDetails_Events]
GO

/****** Object:  Table [dbo].[EventDetails]    Script Date: 3/8/2016 8:48:05 AM ******/
DROP TABLE [dbo].[EventDetails]
GO

/****** Object:  Table [dbo].[EventDetails]    Script Date: 3/8/2016 8:48:05 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[EventDetails](
	[EventDetailID] [int] IDENTITY(1,1) NOT NULL,
	[EventIDFK] [int] NOT NULL,
	[EventText] [varchar](4000) NOT NULL,
 CONSTRAINT [PK_EventDetails] PRIMARY KEY CLUSTERED 
(
	[EventDetailID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[EventDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_EventDetails_Events] FOREIGN KEY([EventIDFK])
REFERENCES [dbo].[Events] ([EventID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[EventDetails] CHECK CONSTRAINT [FK_EventDetails_Events]
GO

USE [ApplicationLogging]
GO

/****** Object:  Table [dbo].[AuditLog]    Script Date: 3/8/2016 8:52:40 AM ******/
DROP TABLE [dbo].[AuditLog]
GO

/****** Object:  Table [dbo].[AuditLog]    Script Date: 3/8/2016 8:52:40 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[AuditLog](
	[AuditLogID] [bigint] IDENTITY(1,1) NOT NULL,
	[ServiceName] [varchar](50) NULL,
	[Category] [varchar](50) NULL,
	[UserName] [varchar](50) NULL,
	[IPAddress] [varchar](50) NULL,
	[ExternalIP] [varchar](50) NULL,
	[Environment] [varchar](25) NULL,
	[ServerName] [varchar](50) NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[TotalSec] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[AuditLogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
USE [ApplicationLogging]
GO

/****** Object:  Table [dbo].[AuditLogDetail]    Script Date: 3/8/2016 8:53:30 AM ******/
DROP TABLE [dbo].[AuditLogDetail]
GO

/****** Object:  Table [dbo].[AuditLogDetail]    Script Date: 3/8/2016 8:53:30 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[AuditLogDetail](
	[AuditLogDetailID] [bigint] IDENTITY(1,1) NOT NULL,
	[AuditLogID] [bigint] NOT NULL,
	[AuditEvent] [varchar](50) NULL,
	[AuditTime] [datetime] NULL,
	[AuditSubject] [varchar](50) NULL,
	[AuditValue] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED 
(
	[AuditLogDetailID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
USE [ApplicationLogging]
GO

EXEC sys.sp_dropextendedproperty @name=N'MS_DiagramPaneCount' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vwEvents'

GO

EXEC sys.sp_dropextendedproperty @name=N'MS_DiagramPane1' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vwEvents'

GO

/****** Object:  View [dbo].[vwEvents]    Script Date: 3/8/2016 8:53:47 AM ******/
DROP VIEW [dbo].[vwEvents]
GO

/****** Object:  View [dbo].[vwEvents]    Script Date: 3/8/2016 8:53:47 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vwEvents]
AS
SELECT     e.EventID, e.TimeStamp, e.ApplicationIDFK, e.EventType, e.EventDescription, e.UserID, e.URL, e.IPAddress, ed.EventText
FROM         dbo.Events AS e LEFT OUTER JOIN
                      dbo.EventDetails AS ed ON e.EventID = ed.EventIDFK

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1[50] 2[25] 3) )"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2[66] 3) )"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 5
   End
   Begin DiagramPane = 
      PaneHidden = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "e"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 121
               Right = 200
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "ed"
            Begin Extent = 
               Top = 6
               Left = 238
               Bottom = 106
               Right = 390
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      PaneHidden = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vwEvents'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vwEvents'
GO




